import { defineStore } from "pinia";
import axios from "axios";

export const useUserStore = defineStore("user", {
    state: () => ({
        menus: []
    }),
    actions: {
        fetchMenus: async function () {
            try {
                const res = await axios.get("http://localhost:8080/api/user/menu", {
                    headers: {
                        "Authorization": "Bearer " + localStorage.getItem("token")
                    }
                });
                console.log('菜单响应数据:', res.data);
                this.menus = res.data;
            } catch (error) {
                console.error('获取菜单数据失败:', error);
            }
        }
    }
});